package com.shizhanzhe.zxbapp.vip;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.shizhanzhe.zxbapp.R;
import com.shizhanzhe.zxbapp.bean.Notice;
import com.shizhanzhe.zxbapp.url.Path;
import com.shizhanzhe.zxbapp.utils.Util;

import java.util.List;

/**
 * Created by zz9527 on 2018/11/1.
 */
public class NoticeAdapter extends BaseAdapter {

    private  LayoutInflater inflate;
    private  List<Notice.DataBean> list;
    private Context context;
    public NoticeAdapter(Context context, List<Notice.DataBean> list) {
        this.list=list;
        this.context=context;
        inflate = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHold holder;
        if (view==null){
            view=inflate.inflate(R.layout.adapter_notice,null);
            holder=new ViewHold();
            holder.title=view.findViewById(R.id.notice_title);
            holder.iv=view.findViewById(R.id.notice_iv);
//            holder.content=view.findViewById(R.id.notice_content);
            holder.time=view.findViewById(R.id.notice_time);
            view.setTag(holder);
        }else {
            holder= (ViewHold) view.getTag();
        }
        Notice.DataBean bean = list.get(i);
        if (!"".equals(bean.getBanner())){
            if (bean.getBanner().contains("http")){
                Glide.with(context).load(bean.getBanner()).into(holder.iv);
            }else {
                Glide.with(context).load(Path.img(bean.getBanner())).into(holder.iv);
            }
            holder.iv.setVisibility(View.VISIBLE);
        }else {
            holder.iv.setVisibility(View.GONE);
        }
        holder.title.setText(bean.getTitle());
//        holder.content.setText("\t\t"+bean.getContent());
        holder.time.setText(Util.getDateTimeFromMillisecond(bean.getAddtime()));
        return view;
    }
    class  ViewHold{
        TextView title;
        TextView content;
        TextView time;
        ImageView iv;
    }
}
